<template>
	<view class="container">
		<u-navbar title="学习记录" is-fixed background="url('https://www.yplm888.com//uploads/20220803/7ed305f9a93ba50b049a7725662b18cc.png') no-repeat"></u-navbar>
		<scroll-view class="" :scroll-y="true" :style="'height:' + scrollH+'rpx;'" @scrolltolower="lowerBottom" refresher-enabled="true"
			:refresher-triggered="triggered" :refresher-threshold="50" @refresherpulling="onPulling"
			@refresherrefresh="onRefresh" @refresherrestore="onRestore" @refresherabort="onAbort">
		<view class="list-data">
			<view v-for="item in dataList" :key="item.id">
				<view class="list" @click="toDetail(item)">
					<image class="img" :src="item.cover_image" mode="scaleToFill"></image>
					<view class="right-box">
						<view class="right u-line-2">
							{{item.title}}
						</view>
						<view class="right-type">
							上次观看：{{item.record}}<text style="margin-left: 20rpx; color: #fe466b;">{{item.type|typeFilter}}</text>
						</view>
					</view>
				</view>
			</view>
		</view>
		<no-thing v-if="dataList.length==0"></no-thing>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		filters:{
			typeFilter(val){
				let type={
					'junshi':'军师',
					'case':'经典案例',
					'share':'经验分享',
					'lecture':'主题讲座',
					'liveBack':'直播回放',
					'team':'组长团队',
					'broandStory':'品牌故事',
					'class':'课程',
					'teamLeader':'组长团队',
					'Journa':'新闻咨询'
				}
				return type[val]
			}
		},
		data() {
			return {
				dataList: [],
				page:1,
				baseUrl: this.$u.http.config.baseUrl,
				scrollH: 0,
				triggered: false,
			};
		},
		onLoad() {
			this._freshing = false;
			this.initData()
		},
		onReachBottom() {
			this.page++
			this.initData()
		},
		onReady() {
			let that = this;
			uni.getSystemInfo({
				success: function(res) {
					that.scrollH = res.windowHeight * 750 / res.windowWidth;
					// #ifdef MP-WEIXIN
					that.scrollH = res.windowHeight * 750 / res.windowWidth - parseInt(res.safeArea.top) - 200;
					// #endif
				}
			});
		},
		methods: {
			onPulling(e) {
				this.triggered = true;
			},
			async onRefresh() {
				if (this._freshing) return;
				this._freshing = true;
				this.page = 1;
				await setTimeout(() => {
					this.triggered = false;
					this._freshing = false;
					this.dataList = []
					this.initData();
				}, 1000);
				uni.showToast({
					title: '刷新成功',
					duration: 1000
				})
			},
			onRestore() {
				this.triggered = false; // 需要重置
				console.log("onRestore");
			},
			onAbort() {
				console.log("onAbort");
			},
			initData() {
				/* let quaryData = {
					curriculum_type: 1,
				}
				let type = ['junshi','case','share','lecture','liveBack','team','broandStory','class','teamLeader','Journa']
				for (let i = 2; i < 11; i++) {
					if(i==6){continue}
					quaryData.curriculum_type = i
					this.$u.api.getStudyOrder(quaryData).then(res => {
						// this.dataList.push(...res.data)
						res.data.forEach(item=>{
							this.dataList.push({
								id: item.data.id,
								cover_image:item.data.cover_image,
								title: item.data.title,
								record: item.second,
								type: type[i-1]
							})
						})
					})
				} */
				let quaryData = {
					page: this.page,
					limit: 10,
					curriculum_type: 8,
				}
				this.$u.api.getStudyOrder(quaryData).then(res => {
					this.dataList.push(...res.data)
					// res.data.forEach(item => {
					// 	this.dataList.push({
					// 		id: item.data.id,
					// 		cover_image:item.data.cover_image,
					// 		title: item.data.title,
					// 		record: item.second,
					// 		type: 'class'
					// 	})
					// })
					
				})
			},
			toDetail(data){
				console.log(this.dataList)
				this.$u.route('/packageB/pages/hotClassDetail/hotClassDetail', {
					id: data.id
				})
				/* if (data.type == 'junshi') {
					console.log('jushi')
					this.$u.route('/pages/junshiDetail/junshiDetail', {
						id: data.id
					})
				} else if (data.type == 'case' || data.type == 'share' || data.type == 'lecture'|| data.type == 'Journa'|| data.type == 'teamLeader') {
					let vip = uni.getStorageSync('userinfo').vip
					if (vip) {
						this.$u.route('/pages/hostpotDetail/hostpotDetail', {
							id: data.id,
							title: data.title,
							pageType: data.type
						})
					} else {
						uni.showToast({
							title: '仅限会员观看',
							duration: 1000,
							icon: 'error',
						})
					}
				} else if (data.type === 'liveBack' || data.type === 'broandStory') {
					if (data.media_type == 0) {
						this.$u.route('/pages/videosDetail/hostpotDetail', {
							id: data.id,
							title: data.name,
							pageType: data.type
						})
					} else {
						this.$u.route('/pages/videosDetail/videosDetail', {
							id: data.id,
							title: data.name,
							pageType: this.pageType
						})
					}
				} else if (data.type === 'team') {
					this.$u.route('/pages/groupDetail/groupDetail', {
						id: data.id
					})
				} else if (data.type === 'class') {
					this.$u.route('/pages/hotClassDetail/hotClassDetail', {
						id: data.id
					})
				} */
			},
			// tab栏切换
			change(index) {
				this.swiperCurrent = index;
				// this.getOrderList(index);
			},
			transition({
				detail: {
					dx
				}
			}) {
				this.$refs.tabs.setDx(dx);
			},
			animationfinish({
				detail: {
					current
				}
			}) {
				this.$refs.tabs.setFinishCurrent(current);
				this.swiperCurrent = current;
				this.current = current;
			},
			// 触底加载
			lowerBottom() {
				console.log('加载了')
				this.page++;
				
				console.log(this.page)
				this.initData();
			}
		}
	};
</script>

<style>
	/* #ifndef H5 */
	page {
		height: 100%;
		background-color: #ffffff;
	}

	/* #endif */
</style>

<style lang="scss" scoped>
	.container {
		margin: 0 auto;
	}

	.list-data {
		margin-top: 20rpx;
		padding-bottom: 40rpx;

		.list {
			margin: 20rpx;
			padding: 20rpx;
			border-radius: 20rpx;
			box-shadow: 0px 0px 12px 0px rgba(0, 0, 0, 0.1);
			display: flex;

			.img {
				height: 150rpx;
				width: 150rpx;
				border-radius: 20rpx;
			}

			.right-box {
				margin-left: 10rpx;

				.right {
					width: 500rpx;
					height: 110rpx;
					font-weight: 700;
				}

				.right-type {
					color: #ccc;
				}
			}
		}
	}
</style>
